package com.ruoyi.contract.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.service.ICommonToolService;
import com.ruoyi.common.utils.ServletUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.ContractMain;
import com.ruoyi.contract.service.IContractMainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同管理Controller
 * 
 * @author yiran
 * @date 2021-04-21
 */
@RestController
@RequestMapping("/contract/main")
public class ContractMainController extends BaseController
{
    @Autowired
    private IContractMainService contractMainService;
    @Autowired
    private ICommonToolService commonService;

    /**
     * 查询合同管理列表
     */
    @PreAuthorize("@ss.hasPermi('contract:main:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractMain contractMain)
    {
        startPage();
        List<ContractMain> list = contractMainService.selectContractMainList(contractMain);
        return getDataTable(list);
    }

    @GetMapping("/createUserCombox")
    public List createUserCombox(){
        String keyWord = ServletUtils.getParameter("keyWord");
        Map parameterMap = ServletUtils.getParameterMap();
        Map<String,String> param = new HashMap<>();
            return commonService.createUserCombox(param);

    }

    @GetMapping("/createDeptCombox")
    public List createDeptCombox(){
        String keyWord = ServletUtils.getParameter("keyWord");
        Map parameterMap = ServletUtils.getParameterMap();
        Map<String,String> param = new HashMap<>();
        return commonService.createDeptCombox();

    }

    /**
     * 导出合同管理列表
     */
    @PreAuthorize("@ss.hasPermi('contract:main:export')")
    @Log(title = "合同管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ContractMain contractMain)
    {
        List<ContractMain> list = contractMainService.selectContractMainList(contractMain);
        ExcelUtil<ContractMain> util = new ExcelUtil<ContractMain>(ContractMain.class);
        return util.exportExcel(list, "合同管理数据");
    }

    /**
     * 获取合同管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:main:query')")
    @GetMapping(value = "/{gid}")
    public AjaxResult getInfo(@PathVariable("gid") String gid)
    {
        return AjaxResult.success(contractMainService.selectContractMainById(gid));
    }

    /**
     * 新增合同管理
     */
    @PreAuthorize("@ss.hasPermi('contract:main:add')")
    @Log(title = "合同管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractMain contractMain)
    {
        return toAjax(contractMainService.insertContractMain(contractMain));
    }

    /**
     * 修改合同管理
     */
    @PreAuthorize("@ss.hasPermi('contract:main:edit')")
    @Log(title = "合同管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractMain contractMain)
    {
        return toAjax(contractMainService.updateContractMain(contractMain));
    }

    /**
     * 删除合同管理
     */
    @PreAuthorize("@ss.hasPermi('contract:main:remove')")
    @Log(title = "合同管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gids}")
    public AjaxResult remove(@PathVariable String[] gids)
    {
        return toAjax(contractMainService.deleteContractMainByIds(gids));
    }
    /**
     * 确认合同管理
     */
    @PreAuthorize("@ss.hasPermi('contract:main:approve')")
    @GetMapping(value = "/approve/{gid}")
    public AjaxResult approve(@PathVariable String gid)
    {
        return toAjax(contractMainService.approveContractMainById(gid));
    }

}
